<?php

/**
 * This file is part of the Pagizer package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright   Copyright (c) 2010 Advisa (http://www.advisa.fr)
 * @author      Pagizer Core Team <team@pagizer.org>
 * @package     pagizer
 * @subpackage  install
 */

class m_install_actions_LanguageAction extends f_core_Action
{
	public function execute()
	{
        $formValues = $this->getFormValues('form');

        $this->addToModel('selectedLang', strtoupper(f_core_Context::getInstance()->getBrowserLanguage()));
        $this->addToModel('langs', f_locale_Manager::getIsoCodes());

        if(!is_null($formValues))
        {
            $config = f_loader_Config::getInstance();
            $config->setParameter('default', 'defaultDocumentLang', $formValues['lang'])->save();
            $this->addToModel('lang', f_locale_Manager::getDatasFromIso($formValues['lang']));
            f_core_Controller::getInstance()->redirect(URL_RELATIVE.'/bo/install/Database');
        }
        else
        {
            $this->setView('input');
        }
	}

	public function validate()
	{
        return f_loader_Config::getInstance()->getParameter('default', 'defaultDocumentLang') == '';
	}

	public function errorHandler()
	{
        $this->addToModel('lang', f_locale_Manager::getDatasFromIso(f_loader_Config::getInstance()->getParameter('default', 'defaultDocumentLang')));
		$this->setView('success');
	}
}